﻿using RndMaterialDisposalService.Attrbutes;
using RndMaterialDisposalService.Models;
using RndMaterialDisposalService.Models.Entitys;
using RndMaterialDisposalService.Models.RequestModel;
using RndMaterialDisposalService.Services.Interface.MaterialDisposal;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace RndMaterialDisposalService.Controllers.MaterialDisposal
{
    /// <summary>
    /// 
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class OrgManagementController : ControllerBase
    {
        private readonly ILogger<OrgManagementController> logger;
        private readonly IOrgConfigurationService orgConfigurationService;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="orgConfigurationService"></param>
        public OrgManagementController(ILogger<OrgManagementController> logger, IOrgConfigurationService orgConfigurationService)
        {
            this.logger = logger;
            this.orgConfigurationService = orgConfigurationService;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="orgManageReq"></param>
        /// <returns></returns>
        [HttpPost("GetOrgConfigList")]
        [PageList]
        public async Task<IActionResult> GetOrgConfigList(OrgManagementReq orgManageReq)
        {
            var result = await orgConfigurationService.GetOrgConfigurationList(orgManageReq);
            var response = ApiResponsePageList<OrgConfigurationDto>.CreatePageListByResult(result.list, orgManageReq.PageIndex, orgManageReq.PageSize, result.count);
            return Ok(response);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="keyword"></param>
        /// <param name="PageIndex"></param>
        /// <param name="PageSize"></param>
        /// <returns></returns>
        [HttpGet("GetOrgListByKeyword")]
        [PageList]
        public async Task<IActionResult> GetOrgListByKeyword(string? keyword, int PageIndex = 1, int PageSize = 10)
        {
            var result = await orgConfigurationService.GetOrgListByKeyword(keyword ?? "", PageIndex, PageSize);
            var response = ApiResponsePageList<OrgConfigurationDto>.CreatePageListByResult(result.list, PageIndex, PageSize, result.count);
            return Ok(response);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost("AddOrgConfig")]
        public async Task<IActionResult> AddOrgConfig(OrgConfigurationDto model)
        {
            model.CreateDate = DateTime.Now;
            var result = await orgConfigurationService.AddOrgConfiguration(model);
            return Ok(result);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost("UpdateOrgConfig")]
        public async Task<IActionResult> UpdateOrgConfig(OrgConfigurationDto model)
        {
            var result = await orgConfigurationService.UpdateOrgConfiguration(model);
            return Ok(result);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sysId"></param>
        /// <returns></returns>
        [HttpPost("DeleteOrgConfig")]
        public async Task<IActionResult> DeleteOrgConfig(Guid sysId)
        {
            logger.LogInformation($"Delete OrgConfig : {sysId}");
            var result = await orgConfigurationService.DeleteOrgConfiguration(sysId);
            return Ok(result);
        }





    }
}
